package kr.hyunist.androidcomplete01saeildamil.ch12;

import java.util.*;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.content.*;
import android.view.*;
import android.widget.*;

public class MultiAdapter extends BaseAdapter {
	LayoutInflater mInflater;
	ArrayList<ListItem> arSrc;

	public MultiAdapter(Context context, ArrayList<ListItem> arItem) {
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.arSrc = arItem;
	}

	@Override
	public int getCount() {
		return arSrc.size();
	}

	@Override
	public Object getItem(int position) {
		return arSrc.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public int getItemViewType(int position) {
		return arSrc.get(position).type;
	}

	//getView가 생성되는 수 조사
	@Override
	public int getViewTypeCount() {
		return 2;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			int res = 0;
			switch (arSrc.get(position).type) {
			case 0:
				res = R.layout.texteditex;
				break;

			case 1:
				res = R.layout.btniconex;
				break;
			}
			
			convertView = mInflater.inflate(res, parent, false);
		}

		switch(arSrc.get(position).type){
		case 0:
			TextView tv1 = (TextView) convertView.findViewById(R.id.textedittvzzzzz);
			tv1.setText(arSrc.get(position).Text);
			EditText et1= (EditText) convertView.findViewById(R.id.texteditetzzzzz);
			et1.setText(arSrc.get(position).EditText);
			break;
			
		case 1:
			Button btn1 = (Button) convertView.findViewById(R.id.btniconexbtnzzz);
			btn1.setText(arSrc.get(position).BtnTest);
			ImageView iv1 = (ImageView) convertView.findViewById(R.id.btniconexivzzz);
			iv1.setImageResource(arSrc.get(position).IconRes);
			break;
		}
		return convertView;
	}

}
